///<reference path="../../../core/model/CommonDto.ts"/>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
import { FormValidatorService } from "../../../core/service/form-validator.service";
import { HttpService } from "../../../core/service/http.service";
import { Register } from "../../../core/model/Register";
import { HttpRes } from "../../../core/model/HttpRes";
import { Router, ActivatedRoute } from "@angular/router";
import { AuthService } from "../../../core/service/auth.service";
import { NzMessageService, NzModalRef, NzModalService } from 'ng-zorro-antd';
import { Login } from "../../../core/model/Login";
import { ClassInfoOutput } from "../../../core/model/ClassInfoDto";
import { PagerSearchInput, PagedResultDto, ElementViewType } from "../../../core/model/CommonDto";


@Component({
  selector: 'app-course-score-edit',
  templateUrl: './course-score-edit.component.html',
  styleUrls: ['../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.scss']
})
export class CourseScoreEditComponent implements OnInit {
  courseScoreId;
  drillScore;
  reportScore;
  constructor(public fb: FormBuilder,
    public FormValidator: FormValidatorService,
    private modal: NzModalService,
    public http: HttpService,
    public router: Router,
    public route: ActivatedRoute,
    public Auth: AuthService) {
    this.newMethod();
  }

  private newMethod() {

    this.courseScoreId = this.route.snapshot.params['id'];
    this.GetOneCourseScore();
  }

  ngOnInit() {

  }

  async GetOneCourseScore() {
    const result = await this.http.get<any>('Course/GetOneCourseScore?id=' + this.courseScoreId);
    this.drillScore = result.drillScore;
    this.reportScore = result.reportScore;
  }

  async save() {
    if (this.drillScore > 100 || this.drillScore < 0 || this.reportScore > 100 || this.reportScore < 0) {
      this.modal.confirm({
        nzTitle: '<i>提示</i>',
        nzContent: '<b>分值范围：0~100</b>',
        nzOnOk: () => {
          window.history.go(-1);
        }
      });
      return;
    }
    const par = { Id: this.courseScoreId, DrillScore: this.drillScore, ReportScore: this.reportScore };
    const result = await this.http.post<any>('Course/UpdateCourseScore', par);
    this.modal.confirm({
      nzTitle: '<i>保存成功</i>',
      nzContent: '<b></b>',
      nzOnOk: () => {
        window.history.go(-1);
      }
    });
  }
  backpage() {
    window.history.go(-1);
  }
}
